package com.learnjava.learnjava1.map;

import com.learnjava.learnjava1.dto.DepartmentDTO;
import com.learnjava.learnjava1.dto.DepartmentShortDTO;
import com.learnjava.learnjava1.jpa.entity.DepartmentEntity;
import org.mapstruct.*;

import java.util.List;

@Mapper(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,componentModel = "spring")
public interface DepartmentMapper {

    @Mapping(target = "company.id", source = "companyId")
    DepartmentEntity toEntity(DepartmentDTO dto);

    @Named(value = "toDto")
    @Mapping(target = "companyId", source = "company.id")
    DepartmentDTO toDto(DepartmentEntity departmentEntity);

    @Mapping(target = "companyId", source = "company.id")
    DepartmentShortDTO toShortDto(DepartmentEntity departmentEntity);

    @IterableMapping(qualifiedByName = "toDto")
    @Mapping(target = "companyId", source = "company.id")
    DepartmentDTO map(DepartmentEntity departmentEntity);

    void update(DepartmentShortDTO departmentShortDTO, @MappingTarget DepartmentEntity departmentEntity);

    List<DepartmentDTO> toDepartmentsDTOList(List<DepartmentEntity> companies);

}
